/*
 * @Author: 耿远风
 * @Date: 2020-07-08 00:41:09
 * @LastEditors: 耿远风
 * @LastEditTime: 2020-10-16 15:00:34
 * @Description: 
 */
import { globalError } from 'src/base/interceptors/httpResult.interceptor';
import { QiniuService } from './../../base/services/qiniu.service';
import { User } from './user.entity';
import {
    Controller,
    Get,
    Post,
    HttpStatus,
    Body,
    Query,
    Req,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CheckLogin } from 'src/base/decorator/login.decorator';

@Controller('/user')
export class UserController {
    constructor(
        private userService: UserService,
        private qiniuService: QiniuService,
    ) {}
    @Post('/wxlogin')
    async params(@Body() body, @Query() query) {
        let { openId } = body;
        let people = await User.ybFindOne({ openId });
        if (!people) {
            people = new User(body);
            if (body.avatarUrl) {
                people.face = await this.qiniuService.qiniuUploadHttpFile(
                    body.avatarUrl,
                );
            }
            await people.save();
        }
        return people;
    }
    @Post('/login')
    async login(@Body() body, @Query() query) {
        let { phone,passWord } = body;
        return this.userService.adminLogin(phone,passWord);
    }
    @Post('/new')
    async getNewInfo(@CheckLogin() uid: string) {
        return await User.findById(uid);
    }
}
